package com.bdqn.design.factory;

import com.bdqn.design.dao.NewsDao;
import com.bdqn.design.dao.impl.NewsDaoMySQLImpl;
import com.bdqn.design.dao.impl.NewsDaoOracleImpl;
import com.bdqn.design.dao.impl.NewsDaoRedisImpl;

/**
 * SimpleFactory
 *
 * @author LILIBO
 * @since 2024/7/4
 */
public class SimpleDaoFactory {

    /**
     * 获取一个NewsDao接口实例
     *
     * @return
     */
    public static NewsDao getMySQLInstance() {
        return new NewsDaoMySQLImpl();
    }

    /**
     * 获取一个NewsDao接口实例
     *
     * @return
     */
    public static NewsDao getOracleInstance() {
        return new NewsDaoOracleImpl();
    }

    /**
     * 获取一个NewsDao接口实例
     *
     * @param key 实现接口的实例key
     * @return
     */
    public static NewsDao getInstance(String key) {
        switch (key) {
            case "mysql":
                return new NewsDaoMySQLImpl();
            case "oracle":
                return new NewsDaoOracleImpl();
            case "redis": // 增加了一个实现就要修改此处代码（违反开闭原则）
                return new NewsDaoRedisImpl();
            default:
                throw new RuntimeException("无效的数据库类型：" + key);
        }
    }

}
